#define _CRT_SECURE_NO_WARNINGS 1
#include<stdbool.h>
#include<stdio.h>

typedef struct TreeNode {
    int val;
    struct TreeNode* left;
    struct TreeNode* right;
    
}BTNode;

bool SameTree(BTNode* p, BTNode* q)
{
    if (p->left == NULL && q->right == NULL)
        return true;

    if (p->left == NULL || q->right == NULL)
        return false;
    if (p->val != q->val)
        return false;
    return SameTree(p->left, q->left) && SameTree(p->right, q->right);

}
bool isSubtree(BTNode* root, BTNode* subRoot) {
    if (root == NULL)
        return false;
    if (SameTree(root, subRoot));
    return true;

    return isSubtree(root->left, subRoot)
        || isSubtree(root->right, subRoot);

}
BTNode* BuyNode(int x)
{
    BTNode* node = (BTNode*)malloc(sizeof(BTNode));
    if (node == NULL)
    {
        perror("malloc fail");
        return NULL;
    }

    node->val = x;
    node->left = NULL;
    node->right = NULL;

    return node;
}
BTNode* CreatTree1()
{
    BTNode* node1 = BuyNode(1);
    BTNode* node2 = BuyNode(2);
    BTNode* node3 = BuyNode(3);
    BTNode* node4 = BuyNode(4);
    BTNode* node5 = BuyNode(5);
    BTNode* node6 = BuyNode(6);
    BTNode* node7 = BuyNode(7);

    node1->left = node2;
    node1->right = node4;
    node2->left = node3;
    node4->left = node5;
    node4->right = node6;
    node3->right = node7;
    return node1;
}
BTNode* CreatTree2()
{
    BTNode* node11 = BuyNode(4);
    BTNode* node12 = BuyNode(1);
    BTNode* node13 = BuyNode(2);
   
    node11->left = node12;
    node11->right = node13;

}

int main()
{
    BTNode* root1 = CreatTree1();
    BTNode* root2 = CreatTree2();

    SameTree( root1,root2);
    isSubtree(root1, root2); 

    return 0;
}